package com.learing.groupChat.handler;

import com.learing.utils.SessionUtil;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@ChannelHandler.Sharable
public class AuthHandler4Single extends ChannelInboundHandlerAdapter {
    // 2. 构造单例
    public static final AuthHandler4Single INSTANCE = new AuthHandler4Single();

    protected AuthHandler4Single(){

    }
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (!SessionUtil.hasLogin(ctx.channel())) {
            ctx.channel().close();
        } else {
            ctx.pipeline().remove(this);
            super.channelRead(ctx, msg);
        }
    }
}
